Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: append sourceURL comment to eval code #13754

Merged
merged 9 commits into from
Mar 30, 2022
Merged

Conversation

connorjclark
Copy link
Collaborator

This allows us to more correctly ignore scripts that we created via the Runtime.evaluate method. The current assumption (that all those scripts would have a blank embedderName) does not hold when considering iframes.

@connorjclark connorjclark requested a review from a team as a code owner March 16, 2022 20:35
@connorjclark connorjclark requested review from adamraine and removed request for a team March 16, 2022 20:35
@connorjclark
Copy link
Collaborator Author

connorjclark commented Mar 16, 2022

oops, this was overlooked

await driver.executionContext.evaluateOnNewDocument(pageFunctions.wrapRequestIdleCallback, {

EDIT

uhhhh looks like it doesn't work for eval on new doc?

image

@connorjclark
Copy link
Collaborator Author

uhhhh looks like it doesn't work for eval on new doc?

False alarm, I was seeing confusing results because Debugger.getScriptSource needs to be run on the target that provided the scriptParsedEvents–scriptIds are not unique across the entire run, but only within the same process :(

That also means we'll need to modify how we refer to scripts internally (again...), and I'm not sure there's an easy fix here.


aside, looks like we gotta ignore some stuff in issues that we cause

image

@@ -97,7 +97,8 @@ class ExecutionContext {
.catch(${pageFunctions.wrapRuntimeEvalErrorInBrowserString})
.then(resolve);
});
}())`,
}())
//# sourceURL=lighthouse-eval.js`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a few underscores to this guy? I feel like someone is using lighthouse-eval.js as their script name somewhere out in the web.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that's the case, then the url property will be the full absolute URL ending with this name. But when we set it via sourceURL it's exactly this string.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think //# sourceURL=lighthouse-eval.js is within the realm of possibilities and it can't hurt to add a few underscores or something.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok will do

@@ -68,8 +84,9 @@ class Scripts extends FRGatherer {
// it also blocks scripts from the same origin but that happen to run in a different process,
// like a worker.
if (event.method === 'Debugger.scriptParsed' && !sessionId) {
// Events without an embedderName (read: a url) are for JS that we ran over the protocol.
if (event.params.embedderName) this._scriptParsedEvents.push(event.params);
if (!isLighthouseRuntimeEvaluateScript(event.params)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: now can we add to the condition above ;)

lighthouse-core/gather/driver/execution-context.js Outdated Show resolved Hide resolved
lighthouse-core/gather/gatherers/scripts.js Show resolved Hide resolved
@connorjclark
Copy link
Collaborator Author

@adamraine LGTM?
@paulirish I've addressed your requested changes

@connorjclark
Copy link
Collaborator Author

oh i shoulda been more clear about #13754 (comment)

only an issue for my WIP branch where we stop ignoring OOPIFs

Copy link
Member

@adamraine adamraine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think my comments are still applicable, but they're nits so LGTM

@@ -97,7 +97,8 @@ class ExecutionContext {
.catch(${pageFunctions.wrapRuntimeEvalErrorInBrowserString})
.then(resolve);
});
}())`,
}())
//# sourceURL=lighthouse-eval.js`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think //# sourceURL=lighthouse-eval.js is within the realm of possibilities and it can't hurt to add a few underscores or something.

@connorjclark connorjclark merged commit 6b2d0f0 into master Mar 30, 2022
@connorjclark connorjclark deleted the eval-source-url branch March 30, 2022 23:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants